package blazej.tablice;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.SwingConstants;

public class SixpackGUI extends JFrame {
	int klik;
	 static Sixpack sixpack=new Sixpack();
	private JPanel contentPane;
	private JTextField textPiwo;
	private JTextField textPiwo2;
	private JTextField textPiwo3;
	private JTextField textPiwo4;
	private JTextField textPiwo5;
	private JTextField textPiwo6;
	private JLabel lblStanPiw;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SixpackGUI frame = new SixpackGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SixpackGUI() {
		this.sixpack=sixpack;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		textPiwo = new JTextField();
		textPiwo.setEditable(false);
		contentPane.add(textPiwo, "8, 2, fill, default");
		textPiwo.setColumns(10);
		textPiwo.setText(sixpack.zawartosc[0][0].getNazwa()+"("+sixpack.zawartosc[0][0].getPromile()+")");
		
		textPiwo2 = new JTextField();
		textPiwo2.setEditable(false);
		contentPane.add(textPiwo2, "8, 4, fill, default");
		textPiwo2.setColumns(10);
		textPiwo2.setText(sixpack.zawartosc[0][1].getNazwa()+" "+"("+sixpack.zawartosc[0][1].getPromile()+")");
		
		textPiwo3 = new JTextField();
		textPiwo3.setEditable(false);
		contentPane.add(textPiwo3, "8, 6, fill, default");
		textPiwo3.setColumns(10);
		textPiwo3.setText(sixpack.zawartosc[0][2].getNazwa()+" "+"("+sixpack.zawartosc[0][2].getPromile()+")");
		
		textPiwo4 = new JTextField();
		textPiwo4.setEditable(false);
		contentPane.add(textPiwo4, "8, 8, fill, default");
		textPiwo4.setColumns(10);
		textPiwo4.setText(sixpack.zawartosc[1][0].getNazwa()+" "+"("+sixpack.zawartosc[1][0].getPromile()+")");
		
		textPiwo5 = new JTextField();
		textPiwo5.setEditable(false);
		contentPane.add(textPiwo5, "8, 10, fill, default");
		textPiwo5.setColumns(10);
		textPiwo5.setText(sixpack.zawartosc[1][1].getNazwa()+" "+"("+sixpack.zawartosc[1][1].getPromile()+")");
		
		textPiwo6 = new JTextField();
		textPiwo6.setEditable(false);
		contentPane.add(textPiwo6, "8, 12, fill, default");
		textPiwo6.setColumns(10);
		textPiwo6.setText(sixpack.zawartosc[1][2].getNazwa()+" "+"("+sixpack.zawartosc[1][2].getPromile()+")");
		
		final JButton btnBrowar = new JButton("We\u015B browarka");
		btnBrowar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				klik++;
				wesPiwo();
				if(klik==6){
					btnBrowar.setVisible(false);
				}
			}
		});
		contentPane.add(btnBrowar, "4, 16");
		
		lblStanPiw = new JLabel("Stan Piw : 6");
		lblStanPiw.setBackground(new Color(255, 255, 0));
		contentPane.add(lblStanPiw, "8, 16");
	}


void wesPiwo(){
	if(klik==1){
		textPiwo.setEnabled(false);
		lblStanPiw.setText("Stan Piw: 5");
		lblStanPiw.setBackground(new Color(255,255,51));
	}
	else if(klik==2){
		textPiwo.setEnabled(false);
		textPiwo2.setEnabled(false);
		lblStanPiw.setText("Stan Piw: 4");
		lblStanPiw.setBackground(new Color(255, 255, 102));
	}
	else if(klik==3){
		textPiwo.setEnabled(false);
		textPiwo2.setEnabled(false);
		textPiwo3.setEnabled(false);
		lblStanPiw.setText("Stan Piw: 3");
		lblStanPiw.setBackground(new Color(255, 255, 102));
	}
	else if(klik==4){
		textPiwo.setEnabled(false);
		textPiwo2.setEnabled(false);
		textPiwo3.setEnabled(false);
		textPiwo4.setEnabled(false);
		lblStanPiw.setText("Stan Piw: 2");
		lblStanPiw.setBackground(new Color(255, 255, 153));	
	}
	else if(klik==5){
		textPiwo.setEnabled(false);
		textPiwo2.setEnabled(false);
		textPiwo3.setEnabled(false);
		textPiwo4.setEnabled(false);
		textPiwo5.setEnabled(false);
		lblStanPiw.setText("Stan Piw: 1");
		lblStanPiw.setBackground(new Color(255, 255, 204));	

	}
	else if(klik==6){
		textPiwo.setEnabled(false);
		textPiwo2.setEnabled(false);
		textPiwo3.setEnabled(false);
		textPiwo4.setEnabled(false);
		textPiwo5.setEnabled(false);
		textPiwo6.setEnabled(false);
		lblStanPiw.setText("Brak Piwa ");
		lblStanPiw.setBackground(new Color(255, 51, 0));	
	}
}

}
